//
//  MBDGroupContactsCell.swift
//  MasterBoy
//
//  Created by kyson on 2024/10/12.
//

import Foundation
import YYText
import SnapKit

class MBDGroupContactsCell : MBDCommonCell {
    var groupContactsLabel : YYLabel!
    var groupContactsTitleLabel : YYLabel!

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.initialize()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
        self.initialize()
    }
    
    override var cellModel: Any!{
        didSet {
            let realCellModel = self.cellModel as! MBDGroupContactsCellModel
            self.groupContactsLabel.textLayout = realCellModel.groupContactsTextLayout
            self.groupContactsTitleLabel.textLayout = realCellModel.groupContactsTitleLayout
            
            groupContactsTitleLabel.snp.updateConstraints { make in
                make.height.equalTo(realCellModel.groupContactsTitleLayout!.textBoundingSize.height)
            }
            
            groupContactsLabel.snp.updateConstraints { make in
                make.height.equalTo(realCellModel.groupContactsTextLayout!.textBoundingSize.height)
            }
            
        }
    }

    func initialize() {
        self.contentView.setDynamicForgroundColor()
        self.commonBackgroundView.setDynamicForgroundColor()

        groupContactsTitleLabel = YYLabel()
        self.commonBackgroundView.addSubview(groupContactsTitleLabel)

        let contactTypeIcon = UIImageView(image: UIImage(named: "ico_wechat"))
        self.commonBackgroundView.addSubview(contactTypeIcon)
        
        groupContactsLabel = YYLabel()
        self.commonBackgroundView.addSubview(groupContactsLabel)
                
        groupContactsTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(MBDGroupContactsCellModel.MarginTop)
            make.left.equalToSuperview().offset(7)
            make.right.equalToSuperview().offset(-7)
            make.height.equalTo(0)
        }
        
        contactTypeIcon.snp.makeConstraints { make in
            make.top.equalTo(groupContactsTitleLabel.snp.bottom).offset(MBDGroupContactsCellModel.MarginBetweenTitleAndDetail)
            make.left.equalTo(groupContactsTitleLabel)
            make.size.equalTo(CGSizeMake(MBDGroupContactsCellModel.IconSize, MBDGroupContactsCellModel.IconSize))
        }
        
        groupContactsLabel.snp.makeConstraints { make in
            make.centerY.equalTo(contactTypeIcon)
            make.left.equalTo(contactTypeIcon.snp.right).offset(MBDGroupContactsCellModel.MarginBetweenIconAndDetail)
            make.height.equalTo(0)
            make.bottom.equalToSuperview().offset(-MBDGroupContactsCellModel.MarginBottom)
        }
    }
}
